<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 本质上，解构的语法属于模式匹配，只要等号两边的模式相同（长得一样）
        // 就可以把右边的值，赋值给左边对应的变量。

        let [a, [[b], c]] = [1, [[2], 3]]
        console.log(a, b, c)

        let [, , d] = ['1', '2', '3']
        console.log(d)

        let [x, , y] = [1, 2, 3]

        let [head, ...tail] = [1, 2, 3, 4]
        console.log(head, tail)

        let [aa, bb, ...cc] = ['a']
        console.log(aa, bb, cc) // 'a' , undefined, []

        // 如果解构不成功，变量的值就是undefined
        let [foo] = []
        let [f1, f2] = [1]
        console.log(foo) // undefined
        console.log(f1, f2) // 1, undefined
    </script>
</body>

</html>